﻿using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using MappingGenerator;
using MappingGenerator.Template;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Oracle.DataAccess.Client;
using System.Data;
using MappingGenerator.Formatting;

namespace UnitTesing
{
    [TestClass]
    public class UnitTest1
    {
        string _connectionString = "User id=appl; password=appl;data source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = nad0019aixd22)(PORT = 1521))(CONNECT_DATA =(SERVICE_NAME = icashqa.brinksinc.com)));";
             
        [TestMethod]
        public void SchemaReader_LoadTable()
        {
            var reader = new OracleSchemaReader(_connectionString);
            var table = reader.GetTable("IDEPOSIT_DEPOSIT");
            var template = new EntityTemplate(table);
            var text=template.TransformText();
            Assert.IsNotNull(text);


        }
        [TestMethod]
        public void EntityTemplate_Render()
        {
            var reader = new OracleSchemaReader(_connectionString);
            var table = reader.GetTable("IDEPOSIT_DEPOSIT");
            //table.Name
            var template = new EntityTemplate(table);
            var text = template.TransformText();
            Assert.IsNotNull(text);


        }
        [TestMethod]
        public void GenerateEntity()
        {
            string savePath = @"c:\mappings";
            if(Directory.Exists(savePath))
                Directory.Delete(savePath,true);

            var generator = new Generator(new OracleSchemaReader(_connectionString));
            generator.OutputFolder = savePath;
            generator.GenerateEntity("IDEPOSIT_DEPOSIT");


        }
        [TestMethod]
        public void GenerateAll()
        {
            string savePath = @"c:\mappings";
            var reader = new OracleSchemaReader(_connectionString);
            var formatter = new DbObjectNameFormatter();
            formatter.ColumnNameConverter = new AllCapsUnderscoreStringFormatter();
            formatter.ColumnNameConverter.PreFixes.AddRange(new string[] { "PK_", "pk_", "FK_", "fk_", "PK", "pk", "FK", "fk" });

            formatter.TableNameConverter = new AllCapsUnderscoreStringFormatter();
            formatter.TableNameConverter.PreFixes.AddRange(new string[] { "tbl", "TBL","IDEPOSIT_" });

            var generator = new Generator(reader);
            generator.Formatter = formatter;

            generator.OutputFolder = savePath;
            generator.EntityClassNamespace = "Brinks.iDeposit.Domain";
            generator.MappingClassNamespace = "Brinks.iDeposit.Persistence";
            List<string> tablenames = new List<string>()
                                          {
                                              "IDEPOSIT_USER_CA_SERVICE_UNITS",
                                              "IDEPOSIT_FOREIGN_DETAIL",
                                              "IDEPOSIT_NOTIFICATION",
                                              "IDEPOSIT_CIT_PICKUP",
                                              "IDEPOSIT_USER_TYPE",
                                              "IDEPOSIT_USER",
                                              "IDEPOSIT_USER_CA_RETAILER",
                                              "IDEPOSIT_DEPOSIT",
                                              "IDEPOSIT_DEPOSIT_DETAIL",
                                              "IDEPOSIT_DEPOSIT_NOTIFICATION",
                                              "IDEPOSIT_DOMAIN_RESOURCE",
                                              "IDEPOSIT_ORDER",
                                              "IDEPOSIT_ORDER_DETAIL",
                                              "IDEPOSIT_PRODUCT_IMAGE",
                                              "IDEPOSIT_VENDOR",
                                              "IDEPOSIT_ERROR_NOTIFICATION",
                                              "IDEPOSIT_DEPOSIT_IMPORT_RECORD"
                                          };
            generator.GenerateAll(tablenames);


        }

    }

   
}
